﻿using FastEndpoints;
using FluentValidation;
using vite_core.Common;
using vite_entity.Entities;

namespace vite_net.Controllers.User.EditUser;

public sealed class Model
{
    public sealed class Eequest_EditUser
    {
        //public string? Avatar { get; set; }
        //public string? DeptCode { get; set; }
        //public string? Email { get; set; }
        //public int? GenderKey { get; set; }
        //public string? Mobile { get; set; }
        //public string? Nickname { get; set; }
        //public string? Username { get; set; }
        //public string[]? RoleCodes { get; set; }
        //public int Id { get; set; }
        //public int Status { get; set; }

        public int Id { get; set; }
        public string? Avatar { get; set; }
        public DateTime? CreateTime { get; set; }
        public string? DeptCode { get; set; }
        public string? DeptName { get; set; }
        public string? Email { get; set; }
        public int? GenderKey { get; set; }
        public string? GenderLabel { get; set; }
        public string? Mobile { get; set; }
        public string? NickName { get; set; }
        public string[] RoleCodes { get; set; }
        public string? RoleNames { get; set; }
        public int Status { get; set; }
        public string? UserName { get; set; }


        public sealed class EditUserValidator : Validator<Eequest_EditUser>
        {
            public EditUserValidator()
            {
                RuleFor(x => x.Id)
                    .NotEmpty()
                    .WithMessage("用户Id是必须的!");

                RuleFor(x => x.DeptCode)
                    .NotEmpty()
                    .WithMessage("部门信息是必须的!");
            }
        }

    }
 
 


    public sealed class Response_EditUser
    {
        public string? Msg { get; set; }
        public int Code { get; set; }
    }



    internal sealed class EditMapper : Mapper<Eequest_EditUser, Response_EditUser, SysUser>
    {
        // public IBaseRepository<SysDept> _baseSysDeptRepository { get; set; }
        public override SysUser ToEntity(Eequest_EditUser r) => new()
        {
            Id = r.Id,
            Username = r.UserName,
            Nickname = r.NickName,
            Gender = r.GenderKey == 0 ? false:true,
            Password = "123456".ToMD5(),
            DeptId = 1,
            Avatar = r.Avatar,
            Mobile = r.Mobile,
            Status = r.Status == 0?false:true,
            Email = r.Email,
            CreateTime = DateTime.Now,
            CreateBy = 1,
            IsDeleted = false
        };
 
 

        /// <summary>
        /// 逻辑删除标识(0-未删除 1-已删除)
        /// </summary>
        public bool? IsDeleted { get; set; }

        public override Response_EditUser FromEntity(SysUser e) => new()
        {
            //Id = e.Id,
            //FullName = e.FullName,
            //UserName = $"USR{e.Id:0000000000}",
            //Age = (DateOnly.FromDateTime(DateTime.UtcNow).DayNumber - e.DateOfBirth.DayNumber) / 365,
        };
    }

}
